using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;

[XmlType(TypeName = "type")]
public class TypeElement
{
    [XmlAttribute("fullname")]
    public string FullName { get; set; }

    [XmlAttribute("preserve")]
    public string Preserve { get; set; }
}

[XmlType(TypeName = "assembly")]
public class AssemblyElement
{
    [XmlAttribute("fullname")]
    public string FullName { get; set; }

    [XmlElement("type")]
    public List<TypeElement> Types { get; set; } = new List<TypeElement>();
}

[XmlRoot(ElementName = "linker")]
public class LinkerElement
{
    [XmlElement("assembly")]
    public List<AssemblyElement> Assemblies { get; set; } = new List<AssemblyElement>();
}

public static class Program
{
    [UnityEditor.MenuItem("Test/testxml")]
    public static void Main()
    {
        string xmlString = System.IO.File.ReadAllText("Assets/Editor/link2.xml");

        XmlSerializer serializer = new XmlSerializer(typeof(LinkerElement));
        using (StringReader reader = new StringReader(xmlString))
        {
            LinkerElement linker = (LinkerElement)serializer.Deserialize(reader);
            foreach (var assembly in linker.Assemblies)
            {
                UnityEngine.Debug.LogError($"Assembly Full Name: {assembly.FullName}");
                foreach (var type in assembly.Types)
                {
                    UnityEngine.Debug.LogError($"  Type Full Name: {type.FullName}, Preserve: {type.Preserve}");
                }
            }
        }
    }
}
